package worktest

import (
	"fmt"
	"time"
)

type person struct {
	name        string
	age         int
	pswd        string
	Sex         string
	friend      *person
	moneyPacket float32
}

var moneyPacket float32
var users = []person{
	{name: "hjj", age: 20, pswd: "111"},
	{name: "mff", age: 19, pswd: "222"},
}

func Login() (bool, time.Time, string, int) {
	fmt.Println("请输入用户名")
	var name string
	fmt.Scanln(&name)

	fmt.Println("请输入密码")
	var pswd string
	fmt.Scanln(&pswd)

	for _, user := range users {
		if name == user.name && pswd == user.pswd {
			fmt.Println("欢迎你", user.name, "你的年龄是：", user.age)
			return true, time.Now(), user.name, user.age
		}
	}

	fmt.Println("用户名或密码错误，请重试。")
	return false, time.Now(), "", 0
}

func Recharge(moneyKind string, amount float32) bool {
	if amount <= 0 {
		fmt.Println("充值金额必须为正数")
		return false
	}
	switch moneyKind {
	case "usd":
		moneyPacket += amount * 7.13
	case "rmb":
		moneyPacket += amount
	case "jp":
		moneyPacket += amount * 0.02
	default:
		fmt.Println("我们只接受美元，人民币，和日元充值")
		return false
	}
	fmt.Println("充值完成，现在的额度是：", moneyPacket)
	return true
}

func OrderFood() {
	fmt.Println("请选择菜单，1. 蛋炒饭，2. 炸酱面，3. 回锅肉")
	if moneyPacket <= 0 {
		fmt.Println("我们这里不赊账，请先充值")
		return
	}
	var menuChoice int
	fmt.Scanln(&menuChoice)
	switch menuChoice {
	case 1:
		if moneyPacket < 5 {
			fmt.Println("你的钱不够吃蛋炒饭")
			return
		}
		moneyPacket -= 5
	case 2:
		if moneyPacket < 7 {
			fmt.Println("你的钱不够吃炸酱面")
			return
		}
		moneyPacket -= 7
	case 3:
		if moneyPacket < 10 {
			fmt.Println("你的钱不够吃回锅肉")
			return
		}
		moneyPacket -= 10
	default:
		fmt.Println("无效选择")
	}
	fmt.Println("用餐完毕，现在钱包还剩:", moneyPacket)
}
